package com.gmrz.uaf.servlet.v1.servlet;

import com.gmrz.uaf.servlet.v1.handler.UAFUserClearInfoRequestHandler;
import com.google.inject.Singleton;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * Created by gmrz-ops on 2017/7/12.
 */
@Singleton
public class UAFUserClearInfoRequestServlet extends HttpServlet {
    private static final Logger LOG = LogManager.getLogger(UAFUserClearInfoRequestServlet.class);

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        ServletInputStream inputStream = req.getInputStream();
        ByteArrayOutputStream content = new ByteArrayOutputStream();
        byte[] b = new byte[1024];
        int lens = -1;
        while ((lens = inputStream.read(b)) > 0) {
            content.write(b, 0, lens);
        }
        String request = content.toString("UTF-8");// 内容
        UAFUserClearInfoRequestHandler uafUserClearInfoRequestHandler = new UAFUserClearInfoRequestHandler();
        String response = uafUserClearInfoRequestHandler.getUserInfo(request);
        resp.getWriter().write(response) ;
    }
}
